/* 
vuex的核心管理对象store  仓库
*/
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  count: 1
}
const mutations = {
  increment(state, num) {
    state.count += num
  }
}
const actions = {
  asyncIncrement ({commit}, num) {
    setTimeout(() => {
      commit('increment', num)
    }, 2000)
  } 
}
const getters = {
  evenOrOdd (state) {
    return state.count %2 === 1 ? '奇数' : '偶数'
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions,
  getters,
})